<?php
/**
 * CK框架 语言类
 * @author wujibing<283109896@qq.com>
 * @version   3.0
 * @category   CkFrameWork
 * @package  CkFrameWork
 * @subpackage lib
 */
final class lang
{
    /**
     * 语言数组
     * @var array
     */
    private static $_lang = array();
    /**
     * 获取语言内容
     * @param string $lang
     * @param Array $args 参数
     * @return string
     */
    public static function getLang($lang,$args = array())
    {
        if(!isset(self::$_lang[$lang]))
        {
            return $lang;
        }
        return vsprintf(self::$_lang[$lang],$args);
    }
    /**
     * 载入框架语言
     * @param string $lang
     */
    public static function loadCKLang($lang)
    {
        $langPath = CK_LANG_DIR.'/'.$lang.'/lang.php';
        self::load($langPath);
    }
    /**
     * 载入程序语言
     * @param string $lang
     */
    public static function loadLang($lang)
    {
        $langPath = CK_APPLICATION_DATA_DIR.'lang/'.CK_APPLICATION_NAME.'_'.$lang.'.php';
        try
        {
            self::load($langPath);
        } catch (Exception $e)
        {
            
        }
    }
    /**
     * 载入语言包
     * @param string $langPath
     * @throws notFoundFile_Exception
     */
    private static function load($langPath)
    {
        if(!file::exists($langPath))
        {
            throw new notFoundFile_Exception($langPath);    
        }
        $tmpLang = require $langPath;
        if(!self::$_lang)
        {
            self::$_lang = $tmpLang;
        } else 
        {
            self::$_lang = array_merge(self::$_lang,$tmpLang);
        }
    }
}